import Vue from 'vue';

/**
 * 防止按钮重复点击
 */

const preventReClick = Vue.directive('preventReClick', {
    inserted(el, binding) {
        el.addEventListener('click', () => {
            if (!el.disabled) {
                el.disabled = true
                el.style.cursor = 'not-allowed'
                el.classList.add('is-disabled')

                setTimeout(() => {
                        el.style.cursor = 'pointer'
                        el.disabled = false
                        el.classList.remove('is-disabled')
                    }, binding.value || 2000) //默认2秒
            }
        })
    }
})



export default preventReClick